package org.boot.fast.core.api.mapper;

import org.apache.ibatis.annotations.*;
import org.boot.fast.core.api.mapper.provider.DynamicSqlProvider;
import org.boot.fast.dao.entity.FastApiConfigDO;

import java.util.List;
import java.util.Map;

@Mapper
public interface DynamicSqlMapper {


    /**
     * 执行动态更新 - 使用Provider；增删改、获取更新结果数
     */
    @UpdateProvider(type = DynamicSqlProvider.class, method = "buildUpdateSql")
    int executeDynamicUpdate(@Param("apiConfig") FastApiConfigDO apiConfig,
                             @Param("originalSql") String originalSql,
                             @Param("params") Map<String, Object> params);

    /**
     * 执行批量动态新增 - 使用Provider；新增多条记录，返回新增记录数
     */
    @UpdateProvider(type = DynamicSqlProvider.class, method = "buildInsertBatchSql")
    int executeDynamicInsertBatch(@Param("apiConfig") FastApiConfigDO apiConfig,
                             @Param("originalSql") String originalSql,
                             @Param("params") List<Map<String, Object>> params);


    /**
     * 执行动态查询 - 使用Provider；获取查询结果列表
     */
    @SelectProvider(type = DynamicSqlProvider.class, method = "buildQuerySql")
    List<Map<String, Object>> executeDynamicQuery(@Param("apiConfig") FastApiConfigDO apiConfig,
                                                  @Param("originalSql") String originalSql,
                                                  @Param("params") Map<String, Object> params);
    /**
     * 获取查询结果总数 - 使用Provider；根据查询条件获取符合条件的记录数
     */
    @SelectProvider(type = DynamicSqlProvider.class, method = "buildCountSql")
    long executeCountQuery(@Param("apiConfig") FastApiConfigDO apiConfig,
                           @Param("originalSql") String originalSql,
                           @Param("params") Map<String, Object> params);

}